package com.ciaojian.core.service;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ciaojian.core.mapper.StoreMapper;
import com.ciaojian.core.mapper.UserMapper;
import com.ciaojian.core.model.Store;
import com.ciaojian.core.model.User;
import com.ciaojian.core.util.UserUtil;

import javax.annotation.Resource;

/**
 * @author Atlakyn
 */
public abstract class UserService<M extends BaseMapper<T>, T> extends ServiceImpl<UserMapper, User> {
    @Resource
    private StoreMapper storeMapper;
    /**
     * 获取用户邀请发型师所属门店
     * @param userId 用户ID
     * @return 用户邀请发型师所属门店
     */
    public Store getUserInviterStore(Integer userId) {
        return storeMapper.getUserInviterStore(userId);
    }

    /**
     * 根据用户id获取昵称
     *
     * @param id 用户id
     * @return 用户昵称
     */
    public String getNickNameById(Integer id) {
        return this.baseMapper.getNickNameById(id);
    }

    /**
     * 根据id获取openId
     *
     * @param id 用户id
     * @return openid
     */
    public String getOpenIdById(Integer id) {
        return UserUtil.getOpenId(id);
    }

    /**
     * 根据用户消费次数来计算用户的属性
     *
     * @param orderNum 用户订单数量
     * @return 生客熟客那些
     * 0次 = 未消费用户
     * 1次 = 首次消费用户
     * 2次-3次 = 生客
     * 4次-5次 = 熟客
     * 5次+ = 深度用户
     */
    public Integer getCustomerTypeByOrderNum(Integer orderNum) {
        int flag;
        switch (orderNum) {
            case 0:
                flag = 0;
                break;
            case 1:
                flag = 1;
                break;
            case 2:
            case 3:
                flag = 2;
                break;
            case 4:
            case 5:
                flag = 3;
                break;
            default:
                flag = 4;
                break;
        }
        return flag;
    }
}
